package com.ddatsh.transaction.service.impl.processunit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ddatsh.transaction.contentbody.login.LoginRequestBody;
import com.ddatsh.transaction.contentbody.login.LoginResponseBody;
import com.ddatsh.transaction.core.exception.ServiceException;
import com.ddatsh.transaction.core.exception.TransException;
import com.ddatsh.transaction.core.lifecycle.processunit.ProcessUnit;
import com.ddatsh.transaction.core.model.TransContext;
import com.ddatsh.transaction.service.LoginService;

public class LoginProcessUnitImpl implements ProcessUnit {
	private Logger logger = LoggerFactory.getLogger(LoginProcessUnitImpl.class);
	private static final String name = "登陆交易处理器";

	private LoginService loginService;
	private LoginResponseBody responseBody;

	private String transCode;
	private int order;

	public void execute(TransContext transContext) {
		logger.trace(this.getName(), transContext.getRequest().getRequestNo());
		LoginRequestBody requestBody = (LoginRequestBody) transContext
				.getRequest().getRequestBody();
		try {
			responseBody = loginService.userLogin(requestBody);
		} catch (ServiceException e) {
			throw new TransException(e.getErrorCode(), e.getErrorMsg());
		}
	}

	public boolean isReturn() {
		return true;
	}


	public String getTransCode() {
		return transCode;
	}

	public int getOrder() {
		return order;
	}

	public String getName() {
		return name;
	}

	public Object getResult() {
		return responseBody;
	}

	public Logger getLogger() {
		return logger;
	}

	public void setLogger(Logger logger) {
		this.logger = logger;
	}

	public LoginService getLoginService() {
		return loginService;
	}

	public void setLoginService(LoginService loginService) {
		this.loginService = loginService;
	}

	public LoginResponseBody getResponseBody() {
		return responseBody;
	}

	public void setResponseBody(LoginResponseBody responseBody) {
		this.responseBody = responseBody;
	}

	public void setTransCode(String transCode) {
		this.transCode = transCode;
	}

	public void setOrder(int order) {
		this.order = order;
	}
	
}
